﻿using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using NetCore.CustomAttributes;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Entities
{
    /// <summary>
    /// 实体类基类 确保只含有基础字段
    /// </summary>
    [Serializable, Description("实体类基类")]
    public abstract class BaseEntity : BaseEntity<int>
    {
    }
    /// <summary>
    /// 泛型实体基类
    /// </summary>
    /// <typeparam name="TPrimaryKey">实体主键类型</typeparam>
    [Serializable, Description("实体类泛型基类")]
    public abstract class BaseEntity<TPrimaryKey> : AggregateRoot<TPrimaryKey>,
        IMayHaveTenant, IHasCreationTime, IHasModificationTime, IHasDeletionTime
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        protected BaseEntity()
        {
            CreationTime = DateTime.Now;
            LastModificationTime = CreationTime;
        }
        /// <summary>
        /// Id字段
        /// </summary>
        [Description("Id字段"), Key, BaseField]
        public override TPrimaryKey Id { get; set; }

        ///// <summary>
        ///// 创建人（外键）
        ///// </summary>
        //[Description("创建人"), BaseField]
        //public TPrimaryKey CreatorId { get; set; }
        ///// <summary>
        ///// 修改人（外键）
        ///// </summary>
        //[Description("修改人"), BaseField]
        //public TPrimaryKey LastModifierId { get; set; }

        ///// <summary>
        ///// 无关联外键(组织机构/集团/公司/部门)
        ///// </summary>
        //[Description("数据外键"), BaseField]
        //public TPrimaryKey OrganizationId { get; set; }

        /// <summary>
        /// 创建人（外键）必须为long?类型 因为Userabp中强制是long类型,自己不再更改
        /// </summary>
        [Description("创建人"), BaseField]
        public int? CreatorId { get; set; }
        /// <summary>
        /// 修改人（外键）必须为long?类型 因为Userabp中强制是long类型,自己不再更改
        /// </summary>
        [Description("修改人"), BaseField]
        public int? LastModifierId { get; set; }

        /// <summary>
        /// 无关联外键(组织机构/集团/公司/部门) 必须为long?类型 因为Userabp中强制是long类型,自己不再更改
        /// </summary>
        [Description("数据外键"), BaseField]
        public int? OrganizationId { get; set; }


        #region 实现接口字段
        /// <summary>
        /// 创建时间
        /// </summary>
        [Description("创建时间"), BaseField]
        public DateTime CreationTime { get; set; }
        /// <summary>
        /// 最近一次更新时间
        /// </summary>
        [Description("更新时间"), BaseField]
        public DateTime? LastModificationTime { get; set; }
        /// <summary>
        /// 是否被软删除
        /// </summary>
        [Description("软删除"), BaseField]
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 删除时间
        /// </summary>
        [Description("删除时间"), BaseField]
        public DateTime? DeletionTime { get; set; }
        /// <summary>
        /// 租户
        /// </summary>
        [Description("租户"), BaseField]
        public int? TenantId { get; set; }
        #endregion

    }

}